<?php
session_start();
include("conexion/Bdd.php");
include("EncabezadoPie.php");	
$bdd = new Bdd;
$USUARIO = $_SESSION['USUARIO'];
$ROL = $_SESSION['ROL'];
$post_ok = $_SESSION['post_ok'];
$valor1 = $_SESSION['msg1'];


?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="utf-8">    
    <link rel="stylesheet" type="text/css" media="screen" href="css/grid_12.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/style.css">
    <link href="css/ui-lightness/jquery-ui-1.10.3.custom.css" rel="stylesheet">
    <link rel="stylesheet" href="js/DataTable/css/demo_table.css">

    <script src="js/jquery-1.9.1.js"></script>
    <script src="js/jquery-ui-1.10.3.custom.js"></script>
    <script src="js/multifile/ajaxupload.js"></script>
    <script type="text/javascript" language="javascript" src="js/DataTable/jquery.dataTables.js"></script>

        
    <script type="text/javascript">
        $(function() {
            $('#tabs').tabs();
            $("#tablaPaginada").dataTable();
        });
        function verInformacionFotografia(elemento){
            $("#divInformacion").show();
            $(document).unbind('click');
            $("#divInformacion").animate({
                "top": $("#"+elemento).offset().top+100,
                "left": $("#"+elemento).offset().left - 20
            }, "fast");

           // Hide bindings
            setTimeout( function() { // Delay for Mozilla
                $(document).click( function() {
                    $(document).unbind('click').unbind('keypress');
                    $("#divInformacion").fadeOut(100);									
                    return false;
                });
                console.log("a");
            }, 0);                      

        }
        function deleteEvent(evnt){
            var mensaje = "Esta seguro de eliminar el registro?";

            var dialogo = '<div id="dialog-confirm" title="Confirmaci\xF3n">';
            dialogo += '<p><span class="ui-icon ui-icon-help" style="float:left; margin:0 7px 20px 0;"></span>' + mensaje + '</p>';
            dialogo += '</div>';

            $("#divAlerts").append(dialogo);
            $("#dialog:ui-dialog").dialog("destroy");
            $("#dialog-confirm").dialog({
                resizable: false,
                height: 180,
                modal: true,
                buttons: {
                    "No": function() {
                        $(this).dialog("close");
                    },
                    "Si": function() {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            url: 'Gestion/Gst3.php?nocache=' + Math.random(),
                            data: {t: 5, evnt: evnt},
                            success: function(json) {
                                if (json[0].resp > 0) {
                                    location.reload();
                                } else {
                                    $("#divMensajes").empty().prepend(getMsgError("El evento no ha sido eliminado, intente nuevamente."));
                                }
                            }
                        });
                    }
                },
                close: function() {

                }
            });        
        
        }

        $(function(){
            $("#divInformacion").click( function() {
                $("#divInformacion").show();
                return false;
            });
            $("#divInformacion").keyup(function(event) {
                if ( event.which === 13 ) {
                    $("#divInformacion").fadeOut();
                    $("#divInformacion").fadeIn(200);
                } else if ( event.which === 27 ) {
                    $(document).unbind('click').unbind('keypress');
                    $("#divInformacion").fadeOut(100);	
                }
            });
        });    
        function getMsgError(msg) {
            return "<div class='alert-box error'>"
                    + "<a style='float: right; margin-right: -20px; margin-top: -5px;'>"
                    + "<img src='images/gtk_close2.png' width='14' height='14' onclick='$(this).parent().parent().fadeOut(500)' title='Cerrar dialogo'/>"
                    + "</a>"
                    + "<span>Error!</span><br>" + msg + "</div>";
        }
    </script>

    <!--[if lt IE 8]>
        <div style=' clear: both; text-align:center; position: relative;'>
            <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
                <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
            </a>
        </div>
    <![endif]-->
        <!--[if lt IE 9]>
        <script type="text/javascript" src="js/html5.js"></script>
        <link rel="stylesheet" type="text/css" media="screen" href="css/ie.css">
    <![endif]-->
</head>
<body>
    <div id="divAlerts"></div>
    <?php  imprimirEncabezado()?>
    <section id="content">


        <div class="clear"></div>
    	<div class="container_12">
            <div style="width: 100%; min-height: 400px; float: left; margin-top: 30px">
                <center>
                    <div class="text-3"><span>Convenios</span></div>
                </center>
                <br>
                <br>        
                <?php
                if($post_ok === 1){
                    echo "<div class='alert-box success'>"
                    . "<a style='float: right; margin-right: -20px; margin-top: -5px;'>"
                    . "<img src='images/gtk_close2.png' width='14' height='14' onclick='$(this).parent().parent().fadeOut(500)' title='Cerrar dialogo'/>"
                    . "</a>"
                    . "<span>Hecho!</span><br>".$valor1."</div>";
                    unset($_SESSION['post_ok']);
                    unset($_SESSION['valor1']);
                }
                ?>
                
                               
                <br>
                <br>
                <div id="divMensajes" ></div>
                <table style="float: right">
                    <tr>
                        <td> 
                            <input type="button" value="Crear Nuevo Consorcio" onclick="location.href='Controlador.php?opcion=2'" />
                        </td>
                        <td> 
                            <input type="button" value="Agregar" onclick="location.href='NuevoConvenio.php'" />
                        </td>
                    </tr>
                        
                </table>
                <br>
                <table class="display" id="tablaPaginada" >
                    <thead>
                        <tr>
                            <th>No. de Consorcio</th>
                            <th>Afiliados</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $query = "select *
                                    from consorcio
                                    ";
                        $rs = $bdd->ejecutarConsulta($query);
                        
                        while($fila = mysqli_fetch_assoc($rs)){
                            echo "<tr class=\"gradeU\" >";
                            echo "<td>". $fila['id_consorcio'] . "</td>";
                            echo "<td>";
                            $query = "select c.id_convenio, concat(cl.nombre, ' ', cl.apellido) nombre,
                                    cl.tipo_cliente
                                    from convenioconsorcio cc
                                    join convenio c on cc.id_convenio = c.id_convenio
                                    join cliente cl on c.id_cliente = cl.id_cliente
                                    where cc.id_consorcio= ".$fila['id_consorcio'];
                            
                            $rs2 = $bdd->ejecutarConsulta($query);
                            while($fila2 = mysqli_fetch_assoc($rs2)){
                                echo "<b>Convenio No. ".$fila2['id_convenio']."</b> (".$fila2['nombre'].")<br>";
                            }
                            
                            echo "</td>";
                            echo "</tr>";
                        }
                        ?>
                        </tbody>
                </table>

            </div>
            <div class="clear"></div>

        </div>
    </section> 


<!--<div id="divInformacion"
     style="display:none;position:absolute;  width:180px; height:90px; 
     background-image: url('images/backgroundmc.png');
     background-repeat: no-repeat;
     padding: 5px 5px 5px 5px ;
     ">
    <span style="float: right; margin-right:8px; cursor: pointer; font-size: 8px" title="cerrar dialogo" onclick="$('#divInformacion').hide(100)"><b>[x]</b></span>
    Nombre:<br>
    <input type="text" style="width: 140px" />
</div>-->

  
    <?=imprimirPie()?>
  
</body>
</html>